<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> 
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>
<%@ page import="java.util.*"%>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>

<html>
<head>
	<title>公告管理</title>
	<script type="text/javascript">
	var datatable_content;
		$(function(){
			initTable();
		});
		
		function initTable(){
			datatable_content = $("#contentTable").dataTable({
			   "bServerSide":true,
	           "sAjaxSource":'${ctx}/notice/page',
	           "fnServerData": callback,
	           "bFilter": false,
	           "bSort": false,
	           "sZeroRecords": "查询无记录！",
	           "bProcessing": true,
	           "oLanguage": {
	               "sUrl": '${ctx}/static/v2/js/plugins/datatables/cn.txt'
	            },
	             "aoColumns":[
	             	 {"mData": null},
	             	 {"mData": null},
	             	 {"mData": null},
	             	 {"mData": null},
	             	 {"mData": null}
	             ],
	             "aoColumnDefs":[
	             	{"aTargets": [0],
		              "mRender": function (data, display, row) {
			        	 	return row.id;
			           }
		            },
	             	{"aTargets": [1],
		              "mRender": function (data, display, row) {
			        		return row.noticeTitle; 
			           }
		            },
		            {"aTargets": [2],
		              "mRender": function (data, display, row) {
		            	  return new Date(row.createTime.time).Format("yyyy-MM-dd hh:mm:ss");
			           }
		            },
		            {"aTargets": [3],
			              "mRender": function (data, display, row) {
			            	  return row.status==1?"置顶":"不置顶";
				           }
			            },
		            {"aTargets": [4],
		              "mRender": function (data, display, row) {
			        		return "<a class=\"btn btn-primary\" href=\"${ctx}/notice/v2_update/"+row.id+"\">更改</a>"+
			        		"<a class=\"btn btn-primary\" href=\"${ctx}/notice/top/"+row.id+"\">置顶</a>"+
			        		"<a class=\"btn btn-danger\" href=\"${ctx}/notice/delete/"+row.id+"\">删除</a>"; 
			           }
		            }
	             ],
			});
		}
		
		function callback( sSource, aoData, fnCallback ) {
		 aoData.push( { "name": "search_LIKE_noticeTitle", "value": $("#search_LIKE_noticeTitle").val()});  
			 //查询参数
		   $.ajax({ 
		       "type": "post",
		       "contentType": "application/json", 
		       "url": sSource,    
		       "dataType": "json",   
		       "data": JSON.stringify(aoData),
		       "success": fnCallback  
		   });    
		}
		
		function query(){
			datatable_content.fnDestroy();
			initTable();
		}
</script>
</head>

<body>
<section class="content">
		<c:if test="${not empty message}">
			<div id="message" class="alert alert-success"><button data-dismiss="alert" class="close">×</button>${message}</div>
		</c:if>
		<div class="row">
			<div class="col-md-12">
			<div class="box box-solid box-primary">
			<div class="box-header">
					<i class="fa fa-search"></i>
					<h3 class="box-title">搜索栏</h3>
					<div class="box-tools pull-right">
						<button class="btn btn-primary btn-sm" data-widget="collapse">
							<i class="fa fa-minus"></i>
						</button>
					</div>
				</div>
				<div class="box-body">
	
			<form class="form-search" action="#">
			 	<label>名称：</label> <input type="text" name="search_LIKE_noticeTitle" id="search_LIKE_noticeTitle" class="input-medium" value="${param.search_LIKE_noticeTitle}" onkeydown='if(event.keyCode==13) {query(); return false;}'> 
			    <button type="button" onclick="query()" class="btn btn-info">搜索</button>
			    <a class="btn btn-info" href="${ctx}/notice/v2_create">新建公告</a>
		    </form>
	    </div>
	</div>
	</div>
	</div>
	
	<div class="form-group row">
		<div class="col-md-12">
			<div class="box box-primary">
				<div class="box-header"></div>
				<div class="box-body">
	<table id="contentTable" class="table table-striped table-bordered table-condensed">
		<thead><tr>
			<th>
			序号
			</th>
			<th>
				公告标题
			</th>
			<th>创建时间</th>
			<th>是否置顶</th>
			<th>管理</th>
		</tr></thead>
		<tbody>
		</tbody>
	</table>
	</div>
	</div>
	</div>
</div>
</section>	
</body>
</html>
